#include <cstdio>

int main( )
{
    int c, i, j, n;
    scanf("%d", &c);
    while ( c-- )
    {
        scanf("%d", &n);
        for ( i = 1; i <= n; i++ )
        {
            for ( j = 1; j <= n; j++ )
            {
                if ( j != 1 )
                    printf(" ");
                printf("%d", i * j);
            }
            printf("\n");
        }
    }
    return 0;
}
